import Vue from 'vue';
import Router from 'vue-router';
import routes from './routes';
import store from '@/utils/store';
import CONFIG from '@/config';

Vue.use(Router);

const Route = new Router({
    routes,
    mode: CONFIG.ROUTER_MODE,
    base: CONFIG.ROUTER_BASE_URL
});

Route.beforeEach(async (to, from, next) => {
    next();
});

Route.setTitle = function (title) {
    document.title = title;
};

Route.afterEach(route => {
    if (route.meta && route.meta.title) {
        Route.setTitle(`${CONFIG.TITLE} - ${route.meta.title}`);
    } else {
        Route.setTitle(`${CONFIG.TITLE}`);
    }
});

export default Route;
